﻿using System;

namespace Topro.Log
{
    using NLog;

    /// <summary>
    /// 日志接口实现
    /// </summary>
    public class LoggerServiceImpl: LoggerService
    {
        /// <summary>
        /// NLog日志对象
        /// </summary>
        private static readonly Logger logger = LogManager.GetLogger("OperLog");

        /// <summary>
        /// 操作日志
        /// </summary>
        /// <param name="log">日志对象</param>
        public void Add(OperLog log)
        {
            var logEventInfo = new LogEventInfo(LogLevel.Info, "OperLog", "Oper Log.");

            logEventInfo.Properties["Level"] = log.Level;
            logEventInfo.Properties["Source"] = log.Source;
            logEventInfo.Properties["Message"] = log.Message;
            logEventInfo.Properties["Exception"] = log.Exception;
            logEventInfo.Properties["Ip"] = log.Ip;
            logEventInfo.Properties["CreatedBy"] = log.CreatedBy;
            logEventInfo.Properties["CreatedDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//yyyy-MM-dd HH:mm:ss.ffffff

            logger.Log(logEventInfo);
        }
    }
}
